    
    {mfdeclre.i}
    {gplabel.i}
    
    define input parameter pWorkOrderId as character no-undo.
    define input parameter pPart        as character no-undo.
    define input parameter pOp          as integer   no-undo.
	define input parameter pIssDate     as date      no-undo.
	define input parameter pSite        as character no-undo.
	define input parameter pQtyReq      as decimal   no-undo.
	
    define variable open_ref like mrp_qty.
    define variable inrecno as recid no-undo.

    if pQtyReq = 0 then return.
    
    for first wo_mstr no-lock where wo_lot = pWorkOrderID :
    end.

    for first pt_mstr no-lock where pt_part = pPart:
    end.


    find first wod_det exclusive-lock where wod_lot = pWorkOrderId and wod_part = pPart and wod_op = pOp no-error.

    if not available wod_det then do:
        create wod_det.
        assign
            wod_lot  = wo_lot
            wod_nbr  = wo_nbr 
            wod_part = pPart
            wod_op   = pOp.
    end.

    assign
        wod_iss_date = pIssDate
        wod_site = pSite
        wod_loc  = pt_loc
        wod_critical = pt_critical
        wod_qty_req  = pQtyReq + wod_qty_req
        wod_bom_qty  = 1.

    find first in_mstr where in_part = wod_part and in_site = wod_site exclusive-lock no-error.

    if not available in_mstr then do:
    
        find first si_mstr where si_site = wod_site no-lock no-error.

        {gprun.i ""gpincr.p""
           "(input no,
             input wod_part,
             input wod_site,
             input if available si_mstr then
                      si_gl_set
                   else """",
             input if available si_mstr then
                      si_cur_set
                   else """",
             input if available pt_mstr then
                      pt_abc
                   else """",
             input if available pt_mstr then
                      pt_avg_int
                   else 0,
             input if available pt_mstr then
                      pt_cyc_int
                   else 0,
             input if available pt_mstr then
                      pt_rctpo_status
                   else """",
             input if available pt_mstr then
                      pt_rctpo_active
                   else no,
             input if available pt_mstr then
                      pt_rctwo_status
                   else """",
             input if available pt_mstr then
                      pt_rctwo_active
                   else no,
             output inrecno)" }
/*GUI*/ if global-beam-me-up then undo, leave.

        find in_mstr where recid(in_mstr) = inrecno exclusive-lock.
    end.

    if available in_mstr then do:
        in_qty_req = in_qty_req + wod_qty_req.
    end.

    find qad_wkfl exclusive-lock where qad_key1 = "MFWORLA" and qad_key2 = wod_lot + wod_part + string(wod_op) no-error.
    if not available qad_wkfl then do:
        create qad_wkfl.
        assign
            qad_key1 = "MFWORLA"
            qad_key2 = wod_lot + wod_part + string(wod_op)
            qad_decfld[1] = wod_bom_qty
            qad_decfld[2] = 1.
    end.

    /* UPDATE MRP_DET WORK ORDER COMPONENTS */
    open_ref = wod_qty_req.

    {mfmrwdel.i "wod_det" wod_part wod_nbr wod_lot """"}

    {mfmrw.i "wod_det" wod_part wod_nbr wod_lot string(wod_op)
        ? wod_iss_date open_ref "DEMAND" WORK_ORDER_COMPONENT wod_site}

    release wod_det.


  
